import React from 'react'
import { useDispatch } from 'react-redux'

const Input = () => {
    const dispatch = useDispatch();
    const add = (e) => {
        if (e.keyCode == 13) {
            dispatch({type:'add_item', item: e.target.value});
            e.target.value = '';
        }
    }
    return (
        <div>
            <h2 style={{display: 'inline-block', margin: '0 30px', verticalAlign: 'middle'}}>TodoList</h2>
            <input type="text" onKeyUp={add}/>
        </div>
    )
}

export default Input
